package com.tju.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tju.shortlink.project.dto.req.ShortLinkPageReqDTO;

import com.tju.shortlink.project.dao.entity.LinkDo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tju.shortlink.project.dto.req.ShortLinkRecycleBinPageReqDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author mxl
 * @since 2024-07-06
 */
public interface LinkMapper extends BaseMapper<LinkDo> {
    /**
     * 短链接访问统计自增
     */
    @Update("UPDATE t_link \n" +
            "SET total_pv = total_pv + #{totalPv}, total_uv = total_uv + #{totalUv}, total_uip = total_uip + #{totalUip} \n" +
            "WHERE gid = #{gid} AND full_short_url = #{fullShortUrl}")
    void incrementStats(@Param("gid") String gid,
                        @Param("fullShortUrl") String fullShortUrl,
                        @Param("totalPv") Integer totalPv,
                        @Param("totalUv") Integer totalUv,
                        @Param("totalUip") Integer totalUip);

    /**
     * 分页统计短链接
     */
    IPage<LinkDo> pageLink(ShortLinkPageReqDTO requestParam);

    /**
     * 分页统计回收站短链接
     */
    IPage<LinkDo> pageRecycleBinLink(ShortLinkRecycleBinPageReqDTO requestParam);
}
